package com.fallsvc.re.javasesets.priorityqueue;

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 * @auther falls_vc
 * description:
 * @date 2025/10/20  20:52
 */
public class Demo1 {
    public static void main(String[] args) {

        int[] array = {2,3,4,5,1};
        MyPriorityQueue m = new MyPriorityQueue();
        m.createHeap(array);
        System.out.println(Arrays.toString(array));

        Integer a = 1;
        Queue<Integer> q = new PriorityQueue<>((x, y)->{
            return y.compareTo(x);
        });
    }
    // 最小k 问题
    public int[] smallestK(int[] arr, int k) {
        int[] ret = new int[k];
        if(k <= 0) return ret;
        // 大根堆
        Queue<Integer> q = new PriorityQueue<>((x, y)->{
            return y.compareTo(x);
        });
        // 存前k
        for(int i = 0; i < k; i++) {
            q.offer(arr[i]);
        }
        for(int i = k;i < arr.length; i++) {
            if(arr[i] < q.peek()) {
                q.poll();
                q.offer(arr[i]);
            }
        }


        for(int i = 0; i < k;i++) {
            ret[i] = q.poll();
        }
        return ret;
    }
    public int[] smallestK2(int[] arr, int k) {
        int[] vec = new int[k];
        Arrays.sort(arr);
        for (int i = 0; i < k; ++i) {
            vec[i] = arr[i];
        }
        return vec;
    }


}
